class Die
	include Enumerable
	def each
		loop do
			yield rand(6) + 1
		end
	end
end

puts "Welcome to 'You Win If You Roll a 6'!"
d = Die.new
d.each do |roll|
	puts "You rolled a #{roll}."
	if roll == 6
		puts "You win!"
		break
	end
end
	
states = %w{NJ NY CT MA VT FL}
p states.take(2)
p states.drop(2)
p states.take_while{|s| /N/.match(s)}
p states.drop_while{|s| /N/.match(s)}

p (1..5).max
p %w{ Ruby C APL Perl Smalltalk }.min
p %w{ Ruby C APL Perl Smalltalk }.min {|a,b| a.size <=> b.size}
p %w{ Ruby C APL Perl Smalltalk }.min_by {|lang| lang.size}
p %w{ Ruby C APL Perl Smalltalk }.minmax_by {|lang| lang.size}

state_hash = {"New York" => "NY", "Maine" => "ME","Alaska" => "AK", "Alabama" => "AL"}
p state_hash.min
p state_hash.min_by {|name, abbr| name}
p state_hash.min_by {|name, abbr| abbr} 

[1,2,3].reverse_each {|e| puts e * 10}

array = %w{ red yellow blue}
array.each.with_index do |color,i|
	puts "Color number #{i} is #{color}"
end
